$('#password').bind('keyup', function (event) {
    if (event.keyCode == "13") {
        userLogin();
    }
});

function userLogin() {
    var loginName = $('#userName').val();
    if (!loginName) {
        alert("请输入账号!");
        return;
    }
    var password = $('#password').val();
    if (!password) {
        alert("请输入密码!");
        return;
    }
    var parm = {};
    parm.loginName = loginName;
    parm.password = window.btoa(password);

    $.ajax({
        type: "post",
        url: ctp + "/user/login",
        cache: false,
        data: parm,
        success: function (result) {
            if (result.code == "200") {
                //返回成功之后跳入首页 index.html
                localStorage.setItem("data_view_token", result.token);
                localStorage.setItem("data_view_user_name", result.data);
                window.location.href = "index";
            } else {
                alert(result.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("网络异常");
        }
    });
}

